package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;
import com.aijk.ehm.dao.mybatis.SysFeedbackMapper;
import com.aijk.ehm.model.SysFeedback;
import com.aijk.ehm.model.SysFeedbackExample;
import com.aijk.ehm.model.qo.SysFeedbackQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统管理_意见反馈
 */
@Service
public class SysFeedbackService {
    private static Logger logger = LoggerFactory.getLogger(SysFeedbackService.class);

    @Autowired
    private SysFeedbackMapper mapper;

    public SysFeedbackExample getExample(SysFeedbackQo qo) {
        SysFeedbackExample example = new SysFeedbackExample();
        SysFeedbackExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (Utils.isNotEmpty(qo.getType())) criteria.andTypeEqualTo(qo.getType());
            if (Utils.isNotEmpty(qo.getUid())) criteria.andUidEqualTo(qo.getUid());
            if (Utils.isNotEmpty(qo.getPlatform())) criteria.andPlatformEqualTo(qo.getPlatform());
            if (Utils.isNotEmpty(qo.getAppCode())) criteria.andAppCodeEqualTo(qo.getAppCode());
            if (Utils.isNotEmpty(qo.getMobile())) criteria.andMobileLike("%" + qo.getMobile() +"%");
            if (Utils.isNotEmpty(qo.getNickname())) criteria.andNicknameLike("%" + qo.getNickname() +"%");
            if (Utils.isNotEmpty(qo.getUsername())) criteria.andUsernameLike("%" + qo.getUsername() +"%");
        }
        return example;
    }

    public int count(SysFeedbackQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(SysFeedback bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(SysFeedback bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public SysFeedback findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<SysFeedback> find(SysFeedbackQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<SysFeedback> page(PagingRequest pagingRequest, SysFeedbackQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<SysFeedback>(mapper.selectByExample(getExample(qo)));
    }
}